package com.henu.col05023.common;

import java.util.Calendar;
import java.util.Date;

public class StrCon {

	public static String equalsNull(Object obj, Object rep) {
		return (obj == null || obj.toString().equals("")) ? rep.toString()
				: obj.toString();
	}

	public static String equalsNull(Object obj) {
		return (obj == null) ? "" : obj.toString();
	}

	public static String nowToString() {
		Calendar calendar = Calendar.getInstance();
		String year = intToString(calendar.get(Calendar.YEAR), 3);
		String month = intToString(calendar.get(Calendar.MONTH)+1, 2);
		String day = intToString(calendar.get(Calendar.DAY_OF_MONTH), 2);
		String hour = intToString(calendar.get(Calendar.HOUR), 2);
		String minute = intToString(calendar.get(Calendar.MINUTE), 2);
		String second = intToString(calendar.get(Calendar.SECOND), 2);
		return year + month + day + hour + minute + second;
	}

	public static String todayToString() {
		Calendar calendar = Calendar.getInstance();
		String year = intToString(calendar.get(Calendar.YEAR), 3);
		String month = intToString(calendar.get(Calendar.MONTH)+1, 2);
		String day = intToString(calendar.get(Calendar.DAY_OF_MONTH), 2);
		return year + month + day;
	}

	public static String intToString(int num, int strlen) {
		String nums = num + "";
		int numlen = nums.length();
		for (int i = 0; i < (strlen - numlen); i++) {
			nums = "0" + nums;
		}
		return nums;
	}
}
